﻿using System;
using System.Reflection;
using System.Collections;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;

namespace AnyOffice.module.dept_select
{
    public partial class single : BasePage
    {
        private string strTemp;
        private int count;
        private StringBuilder stringBuilder;
        public string strDeptList;
        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
      
        public single()
        {
            this.stringBuilder = new StringBuilder();
            this.strDeptList = "";
        }
 

        private void BindTree(ref StringBuilder strDept, int DeptId, string strTemp)
        {
            DataTable table = new DepartmentDao().SelectChildAll(base.Conn, DeptId);
            if (table.Rows.Count > 0)
            {
                strTemp = strTemp + "&nbsp;&nbsp;&nbsp;";
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string strDeptList = this.strDeptList;
                    this.strDeptList = strDeptList + "deptlist[" + this.count.ToString() + "]=\"" + table.Rows[i]["DeptId"].ToString() + "\";\n";
                    this.count++;
                    strDept.Append("<tr class=\"TableControl\">\n");
                    strDept.Append("<td class=\"menulines\" id=\"DEPT_" + table.Rows[i]["DeptId"].ToString() + "\" name=\"" + table.Rows[i]["DeptName"].ToString() + "\" onclick=\"javascript:add_field('" + table.Rows[i]["DeptId"].ToString() + "','" + table.Rows[i]["DeptName"].ToString() + "')\">" + strTemp + "├" + table.Rows[i]["DeptName"].ToString() + "</td>\n");
                    strDept.Append("</tr>\n");
                    this.BindTree(ref strDept, int.Parse(table.Rows[i]["DeptId"].ToString()), strTemp);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.ViewState["ToId"] = (Request.QueryString["ToId"] != null) ? Request.QueryString["ToId"].ToString() : "ToId";
            this.ViewState["ToName"] = (Request.QueryString["ToName"] != null) ? Request.QueryString["ToName"].ToString() : "ToName";
            DataTable table = new DepartmentDao().SelectParentAll(base.Conn);
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    string strDeptList = this.strDeptList;
                    this.strDeptList = strDeptList + "deptlist[" + this.count.ToString() + "]=\"" + table.Rows[i]["DeptId"].ToString() + "\";\n";
                    this.count++;
                    this.stringBuilder.Append("<tr class=\"TableControl\">\n");
                    this.stringBuilder.Append("<td class=\"menulines\" id=\"DEPT_" + table.Rows[i]["DeptId"].ToString() + "\" name=\"" + table.Rows[i]["DeptName"].ToString() + "\" onclick=\"javascript:add_field('" + table.Rows[i]["DeptId"].ToString() + "','" + table.Rows[i]["DeptName"].ToString() + "')\">├" + table.Rows[i]["DeptName"].ToString() + "</td>\n");
                    this.stringBuilder.Append("</tr>\n");
                    this.strTemp = "";
                    this.BindTree(ref this.stringBuilder, int.Parse(table.Rows[i]["DeptId"].ToString()), this.strTemp);
                }
            }
            this.litDept.Text = this.stringBuilder.ToString();
        }


    }
}
